using System;
using System.Collections.Generic;
using System.Text;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Drawing;
using Microsoft.SharePoint;

namespace LenninSoftware.FormEditor
{
    public class FieldLabel: Control
    {
        private FieldInfo _field;

        public FieldInfo Field
        {
            get { return _field; }
            set { _field = value; }
        }

        private IEditForm _editForm;

        public IEditForm EditForm
        {
            get { return _editForm; }
            set { _editForm = value; }
        }

        public FieldLabel(FieldInfo field, IEditForm editForm)
        {
            _field = field;
            _editForm = editForm;
        }

        protected override void CreateChildControls()
        {
            Label label = new Label();
            label.Text = Field.Title;

            Controls.Add(label);

            switch (EditForm.ControlMode)
            {
                case Microsoft.SharePoint.WebControls.SPControlMode.Edit:
                case Microsoft.SharePoint.WebControls.SPControlMode.New:

                    if (Field.Required)
                    {
                        Label required = new Label();
                        required.ForeColor = Color.Red;

                        required.Text = " *";
                        Controls.Add(required);
                    }

                    break;
            }
            
        }
    }
}
